[mypyc] Use faster METH_FASTCALL wrapper functions on Python 3.7+#9894
Merged
Conversation
ilevkivskyi
approved these changes
Jan 18, 2021
ilevkivskyi
left a comment
Member
There was a problem hiding this comment.
LGTM, just one suggestion.
| # This is because CPyArg_ParseStackAndKeywords format string requires | ||
| # them grouped in that way. | ||
| groups = make_arg_groups(real_args) | ||
| reordered_args = reorder_arg_groups(groups) |
Member
There was a problem hiding this comment.
These preparatory steps here are very similar to the legacy wrapper below. Would it make sense to factor them out in a helper?
Collaborator
Author
There was a problem hiding this comment.
Refactored some of the shared code. I didn't share everything, since I'm planning further changes that may only be relevant for new-style wrapper functions.
JukkaL
added a commit
that referenced
this pull request
Jan 23, 2021
Allocate a vectorcall function pointer as a struct field for native classes that include `__call__`, including nested functions. This lets us use METH_FASTCALL wrapper functions with `__call__` methods. See https://www.python.org/dev/peps/pep-0590/ for details of why we jump through these hoops. This makes the `nested_func` microbenchmark about 1.5x faster. Follow-up to #9894.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement faster argument parsing based on METH_FASTCALL on supported
Python versions.
Use
vgetargskeywordsfastextracted from Python 3.9 with some modifications:*argsand**kwargsThe modifications are very similar to what we have in the old-style
argument parsing logic.
The legacy calling convention is still used for
__init__and__call__. I'll add__call__support in a separate PR. I haven't looked into supporting__init__yet.
Here are some benchmark results (on Python 3.8)
However, the above benchmarks are still slower when compiled. I'll continue
working on further improvements after this PR.
Fixes mypyc/mypyc#578.